import 'dart:ui';
import 'package:get/get_utils/get_utils.dart';
import 'package:get/route_manager.dart';

enum Language {
  zhCN,
  enUS,
  zhTW;
}

class LanguageManager {
  static Locale get currentLocale => Get.locale ?? const Locale('zh', 'CN');

  static void switchLanguage(Locale locale) {
    Get.updateLocale(locale);
    _saveLocale(locale);
  }

  static String getDisplayName(Locale locale) {
    switch (locale.toString()) {
      case 'zh_CN':
        return '简体中文';
      case 'zh_TW':
        return '繁體中文';
      case 'en_US':
        return 'English';
      default:
        return '简体中文';
    }
  }

  static Future<void> _saveLocale(Locale locale) async {
    // 实际项目可添加SharedPreferences持久化存储
  }

  static Future<Locale> _getSavedLocale() async {
    // 从存储中读取语言设置
    return currentLocale;
  }

  //改变语言
  static void changeLanguage(Language language) {
    Locale locale;
    switch (language) {
      case Language.zhCN:
        locale = const Locale('zh', 'CN');
        break;
      case Language.enUS:
        locale = const Locale('en', 'US');
        break;
      case Language.zhTW:
        locale = const Locale('zh', 'TW');
        break;
    }
    switchLanguage(locale);
  }
}
